export default {
  data(){
    return {
      day:'00',
      hour:'00',
      minute:'00',
      expiryDate:'2016/12/06 22:0:0',
    }
  },
  methods:{
    countdown(){
      const currentTime = Date.now();
      const time2 = new Date(this.expiryDate).getTime();

      const apartTime = time2 - currentTime;
      let _time = apartTime/1000/60/60;

      this.day = '00';
      this.hour = '00';
      this.minute = '00';

      let padding = function(content){
        return (content+'').length > 1 ? content : '0'+content
      }

      if(_time >= 1){
        this.day = padding(Math.floor(_time));
      }
       if((_time = apartTime/1000/60%60) >= 1){
        this.hour = padding(Math.floor(_time));
      }
       if((_time = apartTime/1000%60) >= 1){
        this.minute = padding(Math.floor(_time));
      }
    }
  },
  ready(){
    this.countdown();
    this.intervalTime = setInterval(()=>{
      this.countdown();
    },1E3)
  },
  destroyed(){
    clearInterval(this.intervalTime)
  }
}
